/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package colloque.servlets;

import colloque.Utilisateur;
import colloque.forms.EvaluerDepotForm;
import colloque.helpers.EvalueHelper;
import colloque.helpers.SecurityHelper;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author James
 */
public class EvaluerDepotArchives extends HttpServlet {

    private static String VUE = "/jsp/EvaluerDepotArchives.jsp";

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        SecurityHelper security = new SecurityHelper(request.getSession());
        if (security.isAuthenticated() == false) {
            response.sendRedirect("Connexion");
        } else {
            Utilisateur utilisateur = (Utilisateur) request.getSession().getAttribute("sessionUtilisateur");
            EvalueHelper evaluations = new EvalueHelper();
            if (request.getParameter("evaluation_id") != null) {
                request.setAttribute("evaluation_select", evaluations.getEvaluationById(Integer.parseInt(request.getParameter("evaluation_id"))));
            }
            request.setAttribute("evaluations", evaluations.getEvaluationsArchivesFromMembre(utilisateur.getUtilisateurid()));
            this.getServletContext().getRequestDispatcher(VUE).forward(request, response);
        }
    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        EvaluerDepotForm form = new EvaluerDepotForm();
        form.updateEvaluation(request);
        response.sendRedirect("EvaluerDepotArchives?submit=ok");
    }
}
